package com.sanpu.kxe.business.repay.provider;

import android.content.Context;
import android.content.Intent;

import com.google.gson.Gson;
import com.sanpu.kxe.business.card.bean.BankInfoOutput;
import com.sanpu.kxe.business.repay.bean.RefundPlanInput;
import com.sanpu.kxe.business.repay.bean.RefundPlanOutput;
import com.sanpu.kxe.business.repay.bean.RepayCreditOutput;
import com.sanpu.kxe.business.repay.contract.RepayConfig;
import com.sanpu.kxe.business.repay.view.AddCreditActivity;
import com.sanpu.kxe.business.repay.view.QueryPlanDetailsActivity;
import com.sanpu.kxe.business.repay.view.QueryPlanNewActivity;
import com.sanpu.kxe.business.repay.view.RateDetailsActivity;
import com.sanpu.kxe.business.repay.view.RefundActivity;
import com.sanpu.kxe.business.repay.view.RefundPlanActivity;
import com.sanpu.kxe.business.repay.view.RepayChannelActivity;
import com.sanpu.kxe.business.repay.view.RepayCreditActivity;
import com.sanpu.kxe.business.repay.view.RepaySupportActivity;
import com.sanpu.kxe.business.repay.view.UpdateCreditActivity;
import com.sanpu.kxe.business.trade.bean.PayCollectionOutput;
import com.sanpu.kxe.utils.IntentTool;

/**
 * Description：代还内部跳转
 * Created by 薛勇军 on 2019/4/10.
 */

public class RepayOpenProvider {

    private static RepayOpenProvider instance;

    public static RepayOpenProvider getInstance() {
        if (instance == null) {
            synchronized (RepayOpenProvider.class) {
                if (instance == null) {
                    instance = new RepayOpenProvider();
                }
            }
        }
        return instance;
    }

    /**
     * 代还首页
     */
    public void openRepayCreditActivity(Context context, PayCollectionOutput collectionOutput, boolean isFinish) {
        Intent intent = new Intent(context, RepayCreditActivity.class);
        intent.putExtra(RepayConfig.INTENT_PAYCOLLECTION, collectionOutput);
        IntentTool.startActivity(context, intent, isFinish);
    }

    /**
     * 费率表
     */
    public void openRateDetailsActivity(Context context) {
        IntentTool.startActivity(context, RateDetailsActivity.class);
    }

    /**
     * 可支持银行
     */
    public void openRepaySupportActivity(Context context, String apprtId) {
        Intent intent = new Intent(context, RepaySupportActivity.class);
        intent.putExtra(RepayConfig.INTENT_APPRTID, apprtId);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 添加信用卡
     */
    public void openAddCreditActivity(Context context, RepayCreditOutput creditOutput, int requestCode) {
        if (creditOutput == null) return;
        Intent intent = new Intent(context, AddCreditActivity.class);
        intent.putExtra(RepayConfig.INTENT_APPRTID, creditOutput.getApprtId());
        if (creditOutput.getCardList() != null) {
            intent.putExtra(RepayConfig.INTENT_CARDLIST, new Gson().toJson(creditOutput.getCardList()));
        }
        IntentTool.startActivityForResult(context, intent, requestCode);
    }

    /**
     * 修改信用卡信息
     */
    public void openUpdateCreditActivity(Context context, BankInfoOutput infoOutput) {
        Intent intent = new Intent(context, UpdateCreditActivity.class);
        intent.putExtra(RepayConfig.INTENT_BANKINFO, infoOutput);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 选择还款渠道
     */
    public void openRepayChannelActivity(Context context, BankInfoOutput infoOutput) {
        Intent intent = new Intent(context, RepayChannelActivity.class);
        intent.putExtra(RepayConfig.INTENT_BANKINFO, infoOutput);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 查询计划
     */
    public void openQueryPlanNewActivity(Context context, String mercCardId) {
        Intent intent = new Intent(context, QueryPlanNewActivity.class);
        intent.putExtra(RepayConfig.INTENT_MERCCARDID, mercCardId);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 代还-还款
     */
    public void openRefundActivity(Context context, PayCollectionOutput collectionOutput, BankInfoOutput infoOutput) {
        if (collectionOutput == null || infoOutput == null) return;
        Intent intent = new Intent(context, RefundActivity.class);
        intent.putExtra(RepayConfig.INTENT_BANKINFO, infoOutput);
        intent.putExtra(RepayConfig.INTENT_APPRTID, collectionOutput.getAppCnlConfId());
        intent.putExtra(RepayConfig.INTENT_MAXAMOUNT, collectionOutput.getMaxTradeAmount());
        intent.putExtra(RepayConfig.INTENT_MINAMOUNT, collectionOutput.getMinTradeAmount());
        intent.putExtra(RepayConfig.INTENT_CREDITMINBALANCE, collectionOutput.getCreditMinBalance());
        intent.putExtra(RepayConfig.INTENT_BALANCEPERCENT, collectionOutput.getBalancePercent());
        intent.putExtra(RepayConfig.INTENT_ISOPTIONALMCC, collectionOutput.isOptionalMcc());
        intent.putExtra(RepayConfig.INTENT_BINDCARDID, collectionOutput.getBindCardId());
        IntentTool.startActivity(context, intent);
    }

    /**
     * 查询计划详情
     */
    public void openQueryPlanDetailsActivity(
            Context context, String repayOrderNo, String planStatus, String tradeTime) {
        Intent intent = new Intent(context, QueryPlanDetailsActivity.class);
        intent.putExtra(RepayConfig.INTENT_REPAYORDERNO, repayOrderNo);
        intent.putExtra(RepayConfig.INTENT_PLANSTATUS, planStatus);
        intent.putExtra(RepayConfig.INTENT_TRADETIME, tradeTime);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 还款详情
     */
    public void openRefundPlanActivity(Context context, RefundPlanOutput planOutput,
                                       RefundPlanInput refundPlanInput, boolean isOptionalMcc) {
        Intent intent = new Intent(context, RefundPlanActivity.class);
        intent.putExtra(RepayConfig.INTENT_REFUNDPLAN, planOutput);
        intent.putExtra(RepayConfig.INTENT_REFUNDPLAN_INPUT, refundPlanInput);
        intent.putExtra(RepayConfig.INTENT_ISOPTIONALMCC, isOptionalMcc);
        IntentTool.startActivity(context, intent);
    }

}
